package com.apes.fn.scm.vipSettle.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.account.tax.model.Tax;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.product.model.Product;
import com.apes.scm.masterdata.product.model.ProductUom;
import com.apes.scm.masterdata.product.model.ServeType;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * @Title: VipUnionSettleItem
 * @Description: 会员联盟结算明细表
 * @author: cyy
 * @create: 2022/7/01 14:42
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = VipUnionSettleItem.CONST_TABLE_NAME)
public class VipUnionSettleItem extends BaseModel {

    public static final String CONST_TABLE_NAME = "vip_union_settle_item";

    @Id
    @Column(name = "id",nullable = false, length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "会员联盟结算表明细表编码", padding = 10)
    @Comment("编码")
    private String id;

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "vip_union_settle_id", referencedColumnName = "id")
    @Comment("会员联盟主表编码")
    private VipUnionSettle vipUnionSettle;

    @NotNull
    @Column(name = "retail_order_id")
    @Comment("付款单编码")
    private String retailOrder;

    @Column(name = "retail_order_item_id")
    @Comment("付款单编码")
    private String retailOrderItem;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品")
    private Product product;

    @Comment("服务类型")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "serve_type_id", referencedColumnName = "id", nullable = false)
    private ServeType serveType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "tax_id", referencedColumnName = "id", nullable = false)
    @Comment("税率")
    private Tax tax;

    @Column(name = "primary_price_unit", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("原销售单价")
    private double primaryPriceUnit = 0;

    @Column(name = "cost_price", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("成本价")
    private double costPrice = 0;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_uom_id", referencedColumnName = "id", nullable = false)
    @Comment("计量单位")
    private ProductUom uom;

    @Comment("销售单价")
    @Column(name = "sale_price", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    private double salePrice = 0;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "vip_alliance", referencedColumnName = "id")
    @Comment("会员联盟组")
    private Enumeration vipAlliance;

    @NotNull
    @Column(name = "vip_balance_type", columnDefinition = "number(2) default 0")
    @Comment("会员余额类型")
    private int vipBalanceType;//(1:保呗;2:卡券;3:红包)

    @Column(name = "amount_used", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("使用金额")
    private double amountUsed = 0;

    @Column(name = "settlement_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("应结金额")
    private double settlementAmount = 0;

    @Column(name = "give_tax", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("应结税额")
    private double giveTax = 0;

    @Column(name = "coupon_discount_type", length = 2, columnDefinition = "NUMBER(1,0) default 0")
    @Comment("卡券抵扣方式")
    private int couponDiscountType = 0; // 抵扣方式(1:面值抵扣,2全额抵扣)

    @Column(name = "coupon_flow", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("卡券引流费")
    private double couponFlow = 0;

    @Column(name = "platform_management_fee", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("平台管理费")
    private double platformManagementFee = 0;
}
